package server.business.utils;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import static java.util.Objects.isNull;

public class Otherutils {


    /**
     * 将以逗号分隔的字符串转成数字数组
     * @param intString 字符串
     * @return
     */
    public static int[] getint(String intString){
        int[] intArr = new int[0];
        if(isNull(intString)){
            intArr = new int[0];
        }else{
            String[] valueArr = intString.split(",");
            intArr = new int[valueArr.length];
            for (int i = 0; i < valueArr.length; i++) {
                intArr[i] = Integer.parseInt(valueArr[i]);
            }
        }
        return intArr;

    }

    /**
     * 将以逗分隔的字符串转为字符串数组
     * @param str 字符串
     * @return
     */
    public static String[] getString(String str){
        String[] stringarr = new String[0];
        if(isNull(stringarr)){
            stringarr = new String[0];
        }else{
            String[] valueArr = str.split(",");
            stringarr = new String[valueArr.length];
            for (int i = 0; i < valueArr.length; i++) {
                stringarr[i] = valueArr[i];
            }
        }
        return stringarr;
    }


    /**
     * 返回系统时间用在历史记录中
     * @return
     */
    public static String gettime(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String date = df.format(new Date());

        return date;
    }

    /**
     * 判断数组中是否有目标值
     * @param arr 数组
     * @param targetValue 目标值
     * @return
     */
    public static boolean useList(String[] arr, String targetValue) {
        return Arrays.asList(arr).contains(targetValue);
    }



}
